package com.refusea.train.utils

/**
 * Created by refusea on 2018/10/22.
 */
object Codes {

    /**
     * @return  [referrerId, schoolId]
     */
    fun decode(code: String): IntArray {
        val offset = code.indexOf('.')
        return if (offset == -1) {
            val v = code.toIntOrNull(16)
            if (v == null) {
                intArrayOf(0, 1)
            } else {
                intArrayOf(v ushr 16, v and 0xFFFF)
            }
        } else {
            val v1 = code.substring(0 until offset)
            val v2 = code.substring(offset + 1 until code.length)
            intArrayOf(v1.toInt(16), v2.toInt(16))
        }
    }

}
